package com.bridgeintelligent.tag.webserver.schedule.service.task;

import com.bridgeintelligent.tag.webserver.schedule.api.ICustomerAmountService;
import com.bridgeintelligent.tag.webserver.schedule.api.ITaskLogService;
import com.bridgeintelligent.tag.webserver.schedule.api.enums.TaskEnum;
import com.bridgeintelligent.tag.webserver.schedule.api.page.HandlePage;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @description
 * @author: grp 2020-07-24 10:24
 **/
@Component
@Slf4j
@AllArgsConstructor
public class CustomerAmountUpdateTask {

    private ICustomerAmountService customerAmountService;
    private ITaskLogService taskLogService;
    /**
     * 每天凌晨6点
     */
    @Scheduled(cron = "0 0 6 * * ?")
    public void updateJob() {
        log.info("更新客群客户数任务 开始");
        HandlePage handlePage;
        int page = 1;
        do{
            handlePage = customerAmountService.updateByPage(page, 1000);
            log.info("更新客群客户数任务：page {}-{}", handlePage.getPage(), handlePage.getMessage());
            page++;
        }while (!handlePage.isFinish());
        log.info("更新客群客户数任务 结束");
        taskLogService.save(TaskEnum.TASK_CUSTOMERS_AMOUNT.getId());
    }
}
